package com.starbaba.spread.view;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.base.common.database.BaseDao;
import com.base.common.util.ObjectUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.opensymphony.xwork2.ModelDriven;
import com.starbaba.common.ResultJson;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.model.db.Short_Link;
import com.starbaba.model.dictionary.Constant;
import com.starbaba.model.utils.HttpConnectionUtils;
import com.starbaba.model.utils.JSONUtils;
import com.starbaba.redis.JedisUtils;

import redis.clients.jedis.Jedis;

public class ShortLinkAction extends BaseAction implements ModelDriven  {

	public void showPage(){
		try {
			BaseDao dao = new BaseDao(Constant.POOL_LIFE);

			String sql = "select * from short_link";
			List<Object> params = new ArrayList<Object>();
			List<Short_Link> listLink = dao.list(sql, Short_Link.class, params);
			for (Short_Link link : listLink) {
				String sourceResult = JSONUtils.toJsonString(link); 
				String slink = link.getShort_link();
				JsonObject result = new JsonObject();
				ResultJson resultJs = new ResultJson();
				resultJs.msg = "添加成功:" + Constant.COMMON_HOST + "share_service/redirect?from=" + slink;
				result.add("result", resultJs.toJSON());
				System.out.println(slink);
				// String key = "redict_" + slink;
				String key = "redict_new_" + slink;
				System.out.println(sourceResult);
				JedisUtils.set(key, sourceResult);
				
			}
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}


	
	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return null;
	}
}
